// pages/recruit/personal/feedback/feedback.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    email: "",
    suggestionarry: ["问题反馈", "合作申请", "功能建议","其他"],
    suggestion: "问题反馈",
    suggindex: 0,
    textlimit: 0,
    textarea: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //
  },
  changeemail:function(e){
    const that = this;
    that.setData({
      email: e.detail.value,
    })
  },
  viewChange: function (e) {
   let index = e.detail.value;
    this.setData({
      suggestion: this.data.suggestionarry[index],
      suggindex: index
    })
  },
  textarea: function(e) {
    console.log(e.detail.value)
    this.setData({
      textlimit: e.detail.value.length,
      textarea: e.detail.value,
    })
  },
  commit: function(e) {
    let title;
    let regemail = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    if(this.data.email == "" || !regemail.test(this.data.email)){
      title = "您输入的邮箱有误"
    } else if (this.data.textarea == "") {
      title = "请输入反馈意见"
    }else {
      console.log("提交意见")
      // 提交成功失败都有提示，然后返回之前的页面。
      getApp().globalData.get("/api/user/suggestion",{
        content: this.data.textarea,
        email: this.data.email
      }).then(res=>{
        if(res.code == 200){
          wx.showToast({
            title: '提交成功',
            icon: "success"
          })
          setTimeout(function(){
            wx.navigateBack({})
          })
        }
      })
      return;
    }
    wx.showToast({
      title: title,
      icon: "none",
      duration: 1000
    })
  }
})